public class MyQueue<T> {
    private final T[] data;
    private int front;
    private int rear;
    private int size;

    // 构造函数，初始化队列
    public MyQueue(int capacity) {
        this.data = (T[]) new Object[capacity]; // 初始化数组
        this.front = 0; // 队首指针初始化为0
        this.rear = 0; // 队尾指针初始化为0
        this.size = 0; // 初始化队列大小为0
    }

    // 入队
    public void push(T item) {
        if (size == data.length) {
            throw new ArrayIndexOutOfBoundsException("Queue is full");
        }
        data[rear] = item;
        rear = (rear + 1) % data.length;
        size++;
    }

    // 出队
    public T pop() {
        if (size == 0) {
            throw new ArrayIndexOutOfBoundsException("Queue is empty");
        }
        T item = data[front];
        front = (front + 1) % data.length;
        size--;
        return item;
    }

    public T peek() {
        if (size == 0) {
            throw new ArrayIndexOutOfBoundsException("Queue is empty");
        }
        return data[front];
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return size == data.length;
    }

    public int getSize() {
        return size;
    }

    public static void main(String[] args) {
        MyQueue<Integer> queue = new MyQueue<>(5);

        // 测试入队操作
        queue.push(1);
        queue.push(2);
        queue.push(3);
        queue.push(4);

        // 测试队列满的情况
        System.out.println("Queue is full: " + queue.isFull()); // 输出 true

        // 测试出队操作
        System.out.println("pop: " + queue.pop()); // 输出 1
        System.out.println("pop: " + queue.pop()); // 输出 2

        // 测试队列状态
        System.out.println("Queue size: " + queue.getSize()); // 输出 2

        // 测试再次入队
        queue.push(5);
        System.out.println("pop: " + queue.pop()); // 输出 3
        System.out.println("pop: " + queue.pop()); // 输出 4
        System.out.println("pop: " + queue.pop()); // 输出 5

        // 队列应该为空
        System.out.println("Queue is empty: " + queue.isEmpty()); // 输出 true
    }
}
